package com.hongliang.netty01.eventloop;

import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.NettyRuntime;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author Hongliang Zhu
 * @create 2021-09-25 11:33
 */
@Slf4j
public class TestEventLoop {
    public static void main(String[] args) {
        EventLoopGroup group = new NioEventLoopGroup(2); // io事件、普通任务、定时任务
        System.out.println(group.next());
        System.out.println(group.next());
        // 回到第一个事件循环对象
        System.out.println(group.next());
        System.out.println(NettyRuntime.availableProcessors());


        // 执行普通任务
        group.next().submit(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("ok");
        });

        log.debug("main");

    }
}
